--
-- Author: shunguo.chen
-- Date: 2017-12-28 11:08:25
--
-- PvpSessionInfo	赛季信息

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	if data then
		self:init(data)
	end
end

-- message SeasonInfo {
--    int32 id = 1;
--    int32 startTime = 3;
--    int32 endTime = 4;
--    int32 lv = 10; 
--    int32 score = 20;
--    bool retrievedSeasonReward = 30; //赛季奖励是否领取,false(表示未领取奖励)
-- }
function ClassRef:init(data)
	self.id = data.id
	self.startTime = data.startTime
	self.endTime = data.endTime
	self.lv = data.lv
	self.score = data.score
	self.retrievedSeasonReward = data.retrievedSeasonReward

	self._dateStr = nil
	self._conf = nil
	self._winExpAry = nil
	self._failExpAry = nil
end

function ClassRef:getTitle()
	return string.format(L("tips_1150021"), self.id)
end

function ClassRef:getDateStr()
	if not self._dateStr then
		local dateS = os.date("*t", math.max(self.startTime, 0))
		local dateE = os.date("*t", math.max(self.endTime, 0))
		self._dateStr = string.format("%s.%s-%s.%s", dateS.month, dateS.day, dateE.month, dateE.day)
	end
	return self._dateStr
end

function ClassRef:getEndDateStr()
	local dateE = os.date("*t", math.max(self.endTime, 0))
	return string.format(L("tips_2000233"), dateE.month, dateE.day)
end

function ClassRef:_initConf()
	if not self._conf then
		self._conf = GD:queryPvpSeasonConf(self.lv)
	end
end

function ClassRef:getLevPercent()
	self:_initConf()
	if self.lv ~= 1 then
		local curExp = self.score - tonumber(self._conf.totalExp)
		local maxExp = tonumber(self._conf.levelupExp)
		return curExp/maxExp*100, curExp, maxExp
	else
		return 100, 1, 1
	end
end

function ClassRef:getFailExp(id)
	self:_initConf()
	if not self._failExpAry then
		local ret = {}
		local ary = string.splitTwice(self._conf.loseExp, {";", "|"}, true)
		for i,v in ipairs(ary) do
			ret[v[1]] = v[2]
		end
		self._failExpAry = ret
	end
	return self._failExpAry[tonumber(id)] or 0
end

function ClassRef:getWinExp(id)
	self:_initConf()
	if not self._winExpAry then
		local ret = {}
		local ary = string.splitTwice(self._conf.winExp, {";", "|"}, true)
		for i,v in ipairs(ary) do
			ret[v[1]] = v[2]
		end
		self._winExpAry = ret
	end
	return self._winExpAry[tonumber(id)] or 0
end

function ClassRef:hasSeasonReward()
	return not self.retrievedSeasonReward
end

function ClassRef:clearSeasonReward()
	self.retrievedSeasonReward = true
end

return ClassRef